#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int takeAttendance(vector<int>& records) {
        int n = records.size();
        int left = 0;
        int right = records.size() - 1;
        while (left < right)
        {
            int mid = left + (right - left) / 2;
            if (records[mid] > mid)
                right = mid;
            else
                left = mid + 1;
        }
        if (records[left] == left)
            return left + 1;
        return left;
    }
};

class Solution {
public:
    int findMin(vector<int>& nums) {
        int left = 0;
        int right = nums.size() - 1;
        while (left < right)
        {
            int mid = left + (right - left) / 2;
            if (nums[mid] <= nums[right])
                right = mid;
            else
                left = mid + 1;
        }
        return nums[right];
    }
};

#include <iostream>
using namespace std;
#include <vector>
int main() {
    int a, b;
    cin >> a >> b;
    vector<int> arr(a + 1);
    vector<long long> dp(a + 1);
    arr[0] = 0;
    for (int i = 1; i <= a; i++)
    {
        cin >> arr[i];
    }
    dp[0] = 0;
    for (int i = 1; i <= a; i++)
    {
        dp[i] = dp[i - 1] + arr[i];
    }
    int left, right;
    while (b--)
    {
        cin >> left >> right;
        cout << dp[right] - dp[left - 1] << endl;
    }
    return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<int>> arr(n + 1, vector<int>(m + 1));
    vector<vector<long long>> dp(n + 1, vector<long long>(m + 1));

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
            cin >> arr[i][j];
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + arr[i][j];
        }
    }

    int row1, len1, row2, len2;
    while (q--)
    {
        cin >> row1 >> len1 >> row2 >> len2;
        cout << dp[row2][len2] - dp[row2][len1 - 1] - dp[row1 - 1][len2] + dp[row1 - 1][len1 - 1] << endl;
    }
    return 0;
}

class Solution {
public:
    int pivotIndex(vector<int>& nums) {
        vector<int> dp(nums.size() + 1);
        for (int i = 1; i <= nums.size(); i++)
            dp[i] = dp[i - 1] + nums[i - 1];
        for (int i = 0; i < nums.size(); i++)
        {
            if (dp[i + 1] - dp[0] == dp[nums.size()] - dp[i])
                return i;
        }
        return -1;
    }
};